package com.joe.test_mybatis_plus.utils;

import lombok.Data;

import java.io.Serializable;
/**
 * @Description   返回数据封装
 * @Author        Joe
 * @Company       Jycx
 * @CreateDate    2021/9/8 11:42
 */
@Data
public class Result implements Serializable {
    private Integer code;//200正常；非200异常
    private String msg;
    private Object data;

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    public Result(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public static Result success(){
        return new Result(200,"操作成功");
    }

    public static Result success(Object data){
        return success(200,"操作成功",data);
    }

    public static Result success(Integer code, String msg, Object data){
        return new Result(code,msg,data);
    }

    public static Result fail(String msg){
        return fail(400,msg,null);
    }

    public static Result fail(String msg, Object data){
        return fail(400,msg,data);
    }

    public static Result fail(Integer code, String msg, Object data){
        return new Result(code,msg,data);
    }

    public static Result fail(){
        return new Result(400,"操作失败");
    }

}
